from .models import School, Task, AddrPoint
from user.models import Address, User
# from user.serializers import UserAddressSerializer, UserInfoSerializer
from server_provider.models import Service
from rest_framework import serializers


class SchoolSerializer(serializers.ModelSerializer):
    class Meta:
        model = School
        fields = '__all__'
        depth = 1


class ServiceSerializer(serializers.ModelSerializer):
    class Meta:
        model = Service
        fields = '__all__'


class TaskSerializer(serializers.ModelSerializer):
    category_id = serializers.PrimaryKeyRelatedField(source='category', queryset=Service.objects.all(), write_only=True,
                                                     required=False)
    from_addr_id = serializers.PrimaryKeyRelatedField(source='from_addr', write_only=True,
                                                      queryset=AddrPoint.objects.all(), required=False)
    to_addr_id = serializers.PrimaryKeyRelatedField(source='to_addr', write_only=True,
                                                    queryset=Address.objects.all(), required=False)
    consumer_id = serializers.PrimaryKeyRelatedField(source='consumer', queryset=User.objects.all(), required=False)
    producer_id = serializers.PrimaryKeyRelatedField(source='producer', queryset=User.objects.all(), required=False)
    school_id = serializers.PrimaryKeyRelatedField(queryset=School.objects.all(), source='school', required=False)

    class Meta:
        model = Task
        fields = '__all__'
        extra_kwargs = {
            "price": {
                "required": False
            }
        }
        depth = 1


class AddrPointSerializer(serializers.ModelSerializer):
    class Meta:
        model = AddrPoint
        fields = ['id', 'name', 'addr', 'type', 'school']

        extra_kwargs = {
            'id': {'read_only': True},
        }
